package com.neusoft.userserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.neusoft.userserver.entity.Role;
import com.neusoft.userserver.entity.Users;
import com.neusoft.userserver.mapper.RoleMapper;
import com.neusoft.userserver.mapper.UsersMapper;
import com.neusoft.userserver.service.IRoleService;
import com.neusoft.userserver.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author liuxp
 * @since 2021-07-08
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Autowired
    UsersMapper usersMapper;
    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Users> getAllCustomerManager() {
        List<Users> users = usersMapper.selectList(null);
        List<Users> list = new ArrayList<>();

        for (Users user : users) {
            Role roleById = roleMapper.getRoleById(user.getUserId());
            if (roleById.getRoleName().equals("CUSTOMER_MGR")) {
                list.add(user);
            }
        }

        return list;
    }

}
